package sum_string;

public class Solution {

    public static int sum(String s) {
        int sum = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            sum += c - '0';
        }
        if (sum >= 10) {
            sum = sum(String.valueOf(sum));
        }
        return sum;
    }

    public static void main(String[] args) {
        System.out.println(sum("9999"));
        System.out.println(sum("123456789"));
        System.out.println(sum("8888"));
    }
}
